package org.melanesia.sql;

import java.util.Collection;
import java.util.LinkedHashMap;
import java.util.Map;

import org.melanesia.converters.JavaToJavaConverter;

/**
 * This is a helper class, for storing call metadata, like input/output
 * parameters, type converters, etc.
 * 
 * @author marcin.kielar
 */
class CallMetaData extends QueryMetaData {

    /** Collection storing output parameters registered with {@link Call}. */
    private final Map<String, OutputParameter> outputParameters = new LinkedHashMap<String, OutputParameter>();

    /**
     * Returns the collection of registered output parameter names.
     * 
     * @return collection of registered output parameter names
     */
    final Collection<String> getOutputParameterNames() {
        return outputParameters.keySet();
    }

    /**
     * Returns the output parameter metadata for the parameter of given name.
     * 
     * @param name
     *            parameter name
     * @return parameter metadata
     */
    final OutputParameter getOutputParameter(final String name) {
        return outputParameters.get(name);
    }

    /**
     * Registers outputParameter.
     * 
     * @param name
     *            parameter name
     * @param parameterClass
     *            parameter class
     */
    final void registerOutputParameter(final String name, final Class<?> parameterClass) {
        outputParameters.put(name, new OutputParameter(name, parameterClass));
    }

    /**
     * Registers outputParameter. This method allows for explicit specification
     * of {@link org.melanesia.converters.JavaToJavaConverter} to be used for
     * this parameter.
     * 
     * @param name
     *            parameter name
     * @param parameterClass
     *            parameter class
     * @param converter
     *            java to java converter
     */
    final void registerOutputParameter(final String name, final Class<?> parameterClass, final JavaToJavaConverter converter) {
        outputParameters.put(name, new OutputParameter(name, parameterClass, converter));
    }
}
